<template>
	<view class="">
		<view class="goods_card2">
			<view class="content" v-for="(item, index) in goodsList" :key="index">
				<view @click="jumpGoodsDetail(item.id)">
					<view class="" style="height: 350rpx;">
						<view class="" style="position: relative;height: 100%;" v-if="item.prescription=='2'">
							<view class="flex flex-column-center"
								style="position: absolute;width: 100%;height:100%;z-index: 50;align-items: center;letter-spacing: 2rpx;">
								<view class="" style="font-size: 24rpx;">处方药依法不展示包装</view>
								<view class="margin-top-xs" style="font-size: 24rpx;">请在药师指导下使用</view>
							</view>
							<image :src="item.picUrls[0] ? item.picUrls[0] : '/static/image/no_pic.png'"
								mode="aspectFill" class="row-img" style="filter: blur(5rpx);"></image>
						</view>
						<image :src="item.picUrls[0] ? item.picUrls[0] : '/static/image/no_pic.png'" mode="aspectFill"
							class="row-img" v-if="item.prescription!='2'"></image>
					</view>
					<view class="goodsInfo">
						<view class="text-black text-bold overflow-1">{{item.name}}</view>						
						<view class="flex-row-between margin-top-sm" v-if="userInfo.enable=='1'&&showShare">
							<view class="text-red1 text-bold">
								<text class="font-18">活动价￥</text>
								<text>{{item.skus[0].salesPrice ? item.skus[0].salesPrice.toFixed(2) : '0.00'}}</text>
							</view>
							<view class="shareBtn" @click.stop="sharePost(item)" v-if="item.id&&item.skus&&gType!='yc'">
								<text class="font-18">分享</text>
								<text>赚</text>
								<text class="font-18">￥</text>
								<text v-if="userInfo.userType==1">{{item.skus && item.skus[0].earning ? item.skus[0].earning.toFixed(2) : '0.00' }}</text>
								<text v-if="userInfo.userType==2">{{item.skus && item.skus[0].earning1 ? item.skus[0].earning1.toFixed(2) : '0.00' }}</text>
							</view>
							<view class="shareBtn1" v-if="item.id&&item.skus&&gType=='yc'" @click.stop="sharePost(item)">分享</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<create-share ref="createShare" :goodsSpu="currentItem"></create-share>
		<login-pop ref="lPop"></login-pop>
	</view>
</template>

<script>
	const app = getApp();
	import api from 'utils/api'
	import loginPop from '@/components/login-pop/login-pop.vue'	
	import createShare from '@/components/create-poster/create-share.vue'	

	export default {
		name: 'goods-card2',
		data() {
			return {
				CustomBar: this.CustomBar,
				theme: app.globalData.theme, //全局颜色变量	
				currentItem: {},
				userInfo:{},
				showShare: false,
				userType: null
			};
		},
		components: {
			createShare
		},
		props: {
			goodsList: {
				type: Array,
				default: () => []
			},
			gType: {
				type: [String || null],
				default: ''
			},
			activityId: {
				type: [String || null],
				default: ''
			}
		},
		onLoad() {},
		mounted() {			
			this.userInfo = uni.getStorageSync('user_info')
			if (this.userInfo && this.userInfo.phone && this.userInfo.userLevelId == 2 && this.userInfo.enable == '1') {
				this.showShare = true
			} else if(this.gType=='yc'&&this.userInfo && this.userInfo.phone&&this.userInfo.userType==3) {
				this.showShare = true
			}
		},
		methods: {
			// 生成分享海报
			sharePost(item) {
				this.currentItem = item
				this.$nextTick(() => {
					this.$refs.createShare.openSharePop()
				})
			},
			// 跳转商品详情
			jumpGoodsDetail(id) {
				if(this.gType=='yc'&&this.userInfo && this.userInfo.phone&&this.userInfo.userType==3) {
					uni.navigateTo({
						url: '/pages/goods/goods-detail/index?id=' + id
					})
				} else {
					app.checkLogin().then(res => {
						uni.navigateTo({
							url: '/pages/goods/goods-detail/index?id=' + id
						})
					}).catch(() => {
						this.$refs.lPop.open()
					})
				}				
			},
		}
	};
</script>
<style scoped>
	.goods_card2 {
		display: flex;
		flex-wrap: wrap;
		justify-content: space-between;
	}

	.goods_card2 .content {
		width: calc(50% - 10rpx);
		background-color: #fff;
		margin-bottom: 20rpx;
		border-radius: 25rpx;
		overflow: hidden;
		box-shadow: 0px 2rpx 2rpx #e5e5e5;
	}

	.goods_card2 .content .row-img {
		width: 100%;
		height: 350rpx;
	}

	.goods_card2 .content .goodsInfo {
		padding: 15rpx 15rpx 20rpx;
	}

	.goods_card2 .content .shareBtn {
		background-image: linear-gradient(90deg, #FF7A2F, #FF001F);
		color: #fff;
		border-radius: 10rpx;
		padding: 4rpx 4rpx;
	}
	
	.goods_card2 .content .shareBtn1 {
		background-image: linear-gradient(90deg, #FF7A2F, #FF001F);
		color: #fff;
		border-radius: 10rpx;
		padding: 4rpx 4rpx;
		width: 100rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 24rpx;
	}
</style>